<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get result data</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mssql-query.html">mssql_query</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mssql-rows-affected.html">mssql_rows_affected</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mssql-result" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mssql_result</h1>
  <p class="verinfo">(PHP 4, PHP 5, PECL odbtp &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">mssql_result</span> &mdash; <span class="dc-title">Get result data</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.mssql-result-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>mssql_result</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$row</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$field</code></span>
   )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>mssql_result()</strong></span> returns the contents of one cell from a
   MS SQL result set. 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mssql-result-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">result</code></em></dt>

     <dd>

      <p class="para">
       The result resource that is being evaluated. This result comes from a
       call to <span class="function"><a href="function.mssql-query.html" class="function">mssql_query()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">row</code></em></dt>

     <dd>

      <p class="para">
       The row number.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">field</code></em></dt>

     <dd>

      <p class="para">
       Can be the field&#039;s offset, the field&#039;s name or the field&#039;s table dot
       field&#039;s name (tablename.fieldname). If the column name has been
       aliased (&#039;select foo as bar from...&#039;), it uses the alias instead of
       the column name.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        Specifying a numeric offset for the <em><code class="parameter">field</code></em>
        argument is much quicker than specifying a 
        <em>fieldname</em> or 
        <em>tablename.fieldname</em> argument.
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mssql-result-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the contents of the specified cell.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mssql-result-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1518">
    <p><strong>Example #1 <span class="function"><strong>mssql_result()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Send&nbsp;a&nbsp;select&nbsp;query&nbsp;to&nbsp;MSSQL<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT&nbsp;[username]&nbsp;FROM&nbsp;[php].[dbo].[userlist]'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Check&nbsp;if&nbsp;there&nbsp;were&nbsp;any&nbsp;records<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">mssql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'No&nbsp;records&nbsp;found'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">mssql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);&nbsp;++</span><span style="color: #0000BB">$i</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">mssql_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'username'</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Free&nbsp;the&nbsp;query&nbsp;result<br /></span><span style="color: #0000BB">mssql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Kalle
Felipe
Emil
Ross
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-1519">
    <p><strong>Example #2 Faster alternative to above example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Send&nbsp;a&nbsp;select&nbsp;query&nbsp;to&nbsp;MSSQL<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT&nbsp;[username]&nbsp;FROM&nbsp;[php].[dbo].[userlist]'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Check&nbsp;if&nbsp;there&nbsp;were&nbsp;any&nbsp;records<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">mssql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'No&nbsp;records&nbsp;found'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'username'</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Free&nbsp;the&nbsp;query&nbsp;result<br /></span><span style="color: #0000BB">mssql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mssql-result-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    When working on large result sets, you should consider using one of the
    functions that fetch an entire row (specified below).  As these functions
    return the contents of multiple cells in one function call, they&#039;re MUCH
    quicker than <span class="function"><strong>mssql_result()</strong></span>.  
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mssql-result-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   Recommended high-performance alternatives:
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mssql-fetch-row.html" class="function" rel="rdfs-seeAlso">mssql_fetch_row()</a> - Get row as enumerated array</span></li>
    <li class="member"><span class="function"><a href="function.mssql-fetch-array.html" class="function" rel="rdfs-seeAlso">mssql_fetch_array()</a> - Fetch a result row as an associative array, a numeric array, or both</span></li>
    <li class="member"><span class="function"><a href="function.mssql-fetch-assoc.html" class="function" rel="rdfs-seeAlso">mssql_fetch_assoc()</a> - Returns an associative array of the current row in the result</span></li>
    <li class="member"><span class="function"><a href="function.mssql-fetch-object.html" class="function" rel="rdfs-seeAlso">mssql_fetch_object()</a> - Fetch row as object</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mssql-query.html">mssql_query</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mssql-rows-affected.html">mssql_rows_affected</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
